<?php
    if(isset($_GET['login']))
        $login=$_GET['login'];

	if(array_key_exists('modyfikuj', $_POST)){
        if(array_key_exists('mod', $_POST)){
            foreach(array_keys($_POST) as $el){
                if($el!='usun' && $el!='modyfikuj'){
                    header("Location: ../../../index.php?login=$login&strona=klienci&opcja=mod&id=".$_POST[$el]);
                }
            }
        }else{
            header("Location: ../../../index.php?login=$login&strona=klienci&opcja=przeglad");
        }
    }else{
        $username='root';
        $password='';
        $database='PomocnikProjektanta';

        $baza = mysql_connect('localhost',$username,$password)
                or  die('Nieudane polaczenie: '.mysql_error());

        @mysql_select_db($database) or die("Nie odnaleziono bazy danych");

        foreach(array_keys($_POST) as $el){
            if($el!='usun' && $el!='modyfikuj'){

                $flaga=0;

                $query = "SELECT * FROM Zamowienie WHERE `IdKlienta`=$el";
                $result=mysql_query($query) or die('zapytanie niudane: '.mysql_error());
                $result = mysql_fetch_row($result);

                if($result>1){
                    $flaga++;
                }

                $query = "SELECT * FROM Umowa WHERE `IdKlienta`=$el";
                $result=mysql_query($query) or die('zapytanie niudane: '.mysql_error());
                $result = mysql_fetch_row($result);

                if($result>1){
                    $flaga++;
                }

                $query = "SELECT * FROM Pelnomocnictwo WHERE `IdKlienta`=$el";
                $result=mysql_query($query) or die('zapytanie niudane: '.mysql_error());
                $result = mysql_fetch_row($result);

                if($result>1){
                    $flaga++;
                }

                if($flaga==0){
                    $query = "DELETE FROM Klient WHERE `idKlienta`=$el";
                    mysql_query($query) or die('zapytanie niudane: '.mysql_error());
                }
            }
        }

        mysql_close($baza);
        header("Location: ../../../index.php?login=$login&strona=klienci&opcja=przeglad");
    }
?>
